<?php
/**
 * +-------------------------------------------------------------
 * |Caption:
 * +-------------------------------------------------------------
 * |Author: Lenny
 * +-------------------------------------------------------------
 * |Email:  1685964109@qq.com
 * +-------------------------------------------------------------
 * |Date:   2024/7/27 上午10:27
 * +-------------------------------------------------------------
 */

namespace app\common\controller;

use app\common\model\Company;
use think\App;

class CompanyController extends CommonController
{
    protected mixed $companyId;

    /**
     * 应用名
     */
    protected string $appName = 'company';
    protected array  $position;

    /**
     * 初始化方法
     * @return void
     */
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->userInfo     = request()->userInfo ?? [];
        $this->uid          = $this->userInfo['id'] ?? 0;
        $this->companyId    = $this->userInfo['company_id'] ?? 0;
        $this->position     = $this->getCompanyPosition();
        $this->defaultWhere = [['company_id', '=', $this->companyId],
        ];
    }

    /**
     * 获取公司位置
     */
    protected function getCompanyPosition(): array
    {
        $info = (new Company())->find($this->companyId);
        return [
                'lng' => $info['lng'] ?? 0,
                'lat' => $info['lat'] ?? 0
        ];
    }
}